package codetest;

import java.io.Serializable;
import java.nio.ByteBuffer;

/**
 * @program: netty
 * @description: 测试用户信息
 * @author: 胡海龙
 * @create: 2021-04-14 22:36:56
 **/
public class UserInfo implements Serializable {

    private String username;
    private int userId;

    public UserInfo buildUsername(String username){
        this.username = username;
        return this;
    }

    public UserInfo buildUserId(int userId){
        this.userId = userId;
        return this;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public byte[] codeC() {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        byte[]bytes = this.getUsername().getBytes();
        buffer.putInt(bytes.length);
        buffer.put(bytes);
        buffer.putInt(this.userId);
        buffer.flip();
        bytes = null;
        byte[]result = new byte[buffer.remaining()];
        buffer.get(result);
        return result;
    }
}
